package java11;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class FilesSample {

    public static void main(String[] args) throws Throwable {
        // =================================
        // 1. readString 读文件内容
        // =================================
        String content = Files.readString(Paths.get("C:\\Windows", "WindowsUpdate.log"), StandardCharsets.UTF_8);
        // =================================
        // 2. writeString 写文件内容
        // =================================
        Files.writeString(Paths.get("C:\\AppData", "data.log"),
                "Hello World",
                StandardCharsets.UTF_8,
                StandardOpenOption.CREATE,
                StandardOpenOption.APPEND);
    }

}